open System.Drawing
open System.Windows.Forms

type HelloWorld() = 
  let frm = new Form(Width = 400, Height = 140)
  let fnt = new Font("Times New Roman", 28.0f)
  let lbl = new Label(Dock = DockStyle.Fill, Font = fnt, TextAlign = ContentAlignment.MiddleCenter)
  do frm.Controls.Add(lbl)
  
  member x.SayHello(name) = 
    let msg = "Hello " + name + "!"
    lbl.Text <- msg
    
  member x.Run() = 
    Application.Run(frm)

let hello1 = new HelloWorld()
hello1.SayHello("dear reader")
hello1.Run()

////////

let numbers = [1..10]
let isOdd(n) = (n%2 = 1)
let square(n) = n * n


List.filter isOdd numbers

List.filter isOdd numbers |> List.map square

let squared =
  numbers
  |> List.filter isOdd
  |> List.map square
  
/////

let num = 42
printfn "%d" num
let msg  = "Answer: " + (num.ToString())
printfn "%s" msg

let qqq = 42 in qqq * qqq

let printCity  cityInfo = 
  printfn "Population of %s is %d."
    (fst cityInfo) (snd cityInfo)
    
let prague = ("Prague", 1188126)
let seattle = ("Seattle", 594210)

printCity prague
printCity seattle

let squareFirst l =
  match l with
    | [] -> 0
    | hd::_ -> hd * hd

squareFirst []


/// Passing in functions in F#
// Adding and multiplying list elements in f#

let rec aggregateList (f:int -> int -> int) init list = 
  match list with
    | [] -> init
    | hd::tl -> 
      let rem = aggregateList f init tl
      f rem hd

let add a b = a + b
let mul a b = a * b

aggregateList add 0 [1..5]
aggregateList mul 2 [1..5]

